home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / DateTimeUtils.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  13.3 KB  |  461 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        DateTimeUtils.h
  3.  
  4.      Contains:    International Date and Time Interfaces (previously in TextUtils)
  5.  
  6.      Version:    Technology:    Mac OS 8.5
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1994-1999 by Apple Computer, Inc., all rights reserved.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17. #ifndef __DATETIMEUTILS__
  18. #define __DATETIMEUTILS__
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21.     #include <ConditionalMacros.h>
  22. #endif
  23.  
  24. #ifndef __MACTYPES__
  25.     #include <MacTypes.h>
  26. #endif
  27.  
  28.  
  29.  
  30.  
  31. #if PRAGMA_ONCE
  32. #pragma once
  33. #endif
  34.  
  35. #ifdef __cplusplus
  36. extern "C" {
  37. #endif
  38.  
  39. #if PRAGMA_IMPORT
  40. #pragma import on
  41. #endif
  42.  
  43. #if PRAGMA_STRUCT_ALIGN
  44.     #pragma options align=mac68k
  45. #elif PRAGMA_STRUCT_PACKPUSH
  46.     #pragma pack(push, 2)
  47. #elif PRAGMA_STRUCT_PACK
  48.     #pragma pack(2)
  49. #endif
  50.  
  51. /*
  52.  
  53.     Here are the current routine names and the translations to the older forms.
  54.     Please use the newer forms in all new code and migrate the older names out of existing
  55.     code as maintainance permits.
  56.     
  57.     New Name                    Old Name(s)
  58.     
  59.     DateString                    IUDatePString IUDateString 
  60.     InitDateCache
  61.     LongDateString                IULDateString
  62.     LongTimeString                IULTimeString
  63.     StringToDate                String2Date
  64.     StringToTime                                
  65.     TimeString                    IUTimeString IUTimePString
  66.     LongDateToSeconds            LongDate2Secs
  67.     LongSecondsToDate            LongSecs2Date
  68.     DateToSeconds                Date2Secs
  69.     SecondsToDate                Secs2Date
  70.  
  71.  
  72.     Carbon only supports the new names.  The old names are undefined for Carbon targets.
  73.     This is true for C, Assembly and Pascal.
  74.     
  75.     InterfaceLib always has exported the old names.  For C macros have been defined to allow
  76.     the use of the new names.  For Pascal and Assembly using the new names will result
  77.     in link errors. 
  78.     
  79. */
  80.  
  81.  
  82. typedef SInt16 ToggleResults;
  83. enum {
  84.                                                                 /* Toggle results */
  85.     toggleUndefined                = 0,
  86.     toggleOK                    = 1,
  87.     toggleBadField                = 2,
  88.     toggleBadDelta                = 3,
  89.     toggleBadChar                = 4,
  90.     toggleUnknown                = 5,
  91.     toggleBadNum                = 6,
  92.     toggleOutOfRange            = 7,                            /*synonym for toggleErr3*/
  93.     toggleErr3                    = 7,
  94.     toggleErr4                    = 8,
  95.     toggleErr5                    = 9
  96. };
  97.  
  98. enum {
  99.                                                                 /* Date equates */
  100.     smallDateBit                = 31,                            /*Restrict valid date/time to range of Time global*/
  101.     togChar12HourBit            = 30,                            /*If toggling hour by char, accept hours 1..12 only*/
  102.     togCharZCycleBit            = 29,                            /*Modifier for togChar12HourBit: accept hours 0..11 only*/
  103.     togDelta12HourBit            = 28,                            /*If toggling hour up/down, restrict to 12-hour range (am/pm)*/
  104.     genCdevRangeBit                = 27,                            /*Restrict date/time to range used by genl CDEV*/
  105.     validDateFields                = -1,
  106.     maxDateField                = 10
  107. };
  108.  
  109. enum {
  110.     eraMask                        = 0x0001,
  111.     yearMask                    = 0x0002,
  112.     monthMask                    = 0x0004,
  113.     dayMask                        = 0x0008,
  114.     hourMask                    = 0x0010,
  115.     minuteMask                    = 0x0020,
  116.     secondMask                    = 0x0040,
  117.     dayOfWeekMask                = 0x0080,
  118.     dayOfYearMask                = 0x0100,
  119.     weekOfYearMask                = 0x0200,
  120.     pmMask                        = 0x0400,
  121.     dateStdMask                    = 0x007F                        /*default for ValidDate flags and ToggleDate TogglePB.togFlags*/
  122. };
  123.  
  124.  
  125. typedef SInt8 LongDateField;
  126. enum {
  127.     eraField                    = 0,
  128.     yearField                    = 1,
  129.     monthField                    = 2,
  130.     dayField                    = 3,
  131.     hourField                    = 4,
  132.     minuteField                    = 5,
  133.     secondField                    = 6,
  134.     dayOfWeekField                = 7,
  135.     dayOfYearField                = 8,
  136.     weekOfYearField                = 9,
  137.     pmField                        = 10,
  138.     res1Field                    = 11,
  139.     res2Field                    = 12,
  140.     res3Field                    = 13
  141. };
  142.  
  143.  
  144. typedef SInt8 DateForm;
  145. enum {
  146.     shortDate                    = 0,
  147.     longDate                    = 1,
  148.     abbrevDate                    = 2
  149. };
  150.  
  151. enum {
  152.                                                                 /* StringToDate status values */
  153.     fatalDateTime                = 0x8000,                        /* StringToDate and String2Time mask to a fatal error */
  154.     longDateFound                = 1,                            /* StringToDate mask to long date found */
  155.     leftOverChars                = 2,                            /* StringToDate & Time mask to warn of left over characters */
  156.     sepNotIntlSep                = 4,                            /* StringToDate & Time mask to warn of non-standard separators */
  157.     fieldOrderNotIntl            = 8,                            /* StringToDate & Time mask to warn of non-standard field order */
  158.     extraneousStrings            = 16,                            /* StringToDate & Time mask to warn of unparsable strings in text */
  159.     tooManySeps                    = 32,                            /* StringToDate & Time mask to warn of too many separators */
  160.     sepNotConsistent            = 64,                            /* StringToDate & Time mask to warn of inconsistent separators */
  161.     tokenErr                    = 0x8100,                        /* StringToDate & Time mask for 'tokenizer err encountered' */
  162.     cantReadUtilities            = 0x8200,
  163.     dateTimeNotFound            = 0x8400,
  164.     dateTimeInvalid                = 0x8800
  165. };
  166.  
  167. typedef short                             StringToDateStatus;
  168. typedef StringToDateStatus                 String2DateStatus;
  169.  
  170. struct DateCacheRecord {
  171.     short                             hidden[256];                /* only for temporary use */
  172. };
  173. typedef struct DateCacheRecord            DateCacheRecord;
  174.  
  175. typedef DateCacheRecord *                DateCachePtr;
  176.  
  177. struct DateTimeRec {
  178.     short                             year;
  179.     short                             month;
  180.     short                             day;
  181.     short                             hour;
  182.     short                             minute;
  183.     short                             second;
  184.     short                             dayOfWeek;
  185. };
  186. typedef struct DateTimeRec                DateTimeRec;
  187.  
  188. typedef SInt64                             LongDateTime;
  189.  
  190. union LongDateCvt {
  191.     SInt64                             c;
  192.     struct {
  193.         UInt32                             lHigh;
  194.         UInt32                             lLow;
  195.     }                                 hl;
  196. };
  197. typedef union LongDateCvt                LongDateCvt;
  198.  
  199. union LongDateRec {
  200.     struct {
  201.         short                             era;
  202.         short                             year;
  203.         short                             month;
  204.         short                             day;
  205.         short                             hour;
  206.         short                             minute;
  207.         short                             second;
  208.         short                             dayOfWeek;
  209.         short                             dayOfYear;
  210.         short                             weekOfYear;
  211.         short                             pm;
  212.         short                             res1;
  213.         short                             res2;
  214.         short                             res3;
  215.     }                                 ld;
  216.     short                             list[14];                    /*Index by LongDateField!*/
  217.     struct {
  218.         short                             eraAlt;
  219.         DateTimeRec                     oldDate;
  220.     }                                 od;
  221. };
  222. typedef union LongDateRec                LongDateRec;
  223.  
  224. typedef SInt8                             DateDelta;
  225.  
  226. struct TogglePB {
  227.     long                             togFlags;                    /*caller normally sets low word to dateStdMask=$7F*/
  228.     ResType                         amChars;                    /*from 'itl0', but uppercased*/
  229.     ResType                         pmChars;                    /*from 'itl0', but uppercased*/
  230.     long                             reserved[4];
  231. };
  232. typedef struct TogglePB                    TogglePB;
  233. /*
  234.     These routine are available in Carbon with their new name
  235. */
  236. EXTERN_API( void )
  237. DateString                        (long                     dateTime,
  238.                                  DateForm                 longFlag,
  239.                                  Str255                 result,
  240.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  241.  
  242. EXTERN_API( void )
  243. TimeString                        (long                     dateTime,
  244.                                  Boolean                 wantSeconds,
  245.                                  Str255                 result,
  246.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  247.  
  248. EXTERN_API( void )
  249. LongDateString                    (LongDateTime *            dateTime,
  250.                                  DateForm                 longFlag,
  251.                                  Str255                 result,
  252.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  253.  
  254. EXTERN_API( void )
  255. LongTimeString                    (LongDateTime *            dateTime,
  256.                                  Boolean                 wantSeconds,
  257.                                  Str255                 result,
  258.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  259.  
  260.  
  261. /*
  262.     These routine are available in Carbon and InterfaceLib with their new name
  263. */
  264. EXTERN_API( OSErr )
  265. InitDateCache                    (DateCachePtr             theCache)                            FOURWORDINLINE(0x2F3C, 0x8204, 0xFFF8, 0xA8B5);
  266.  
  267. EXTERN_API( StringToDateStatus )
  268. StringToDate                    (Ptr                     textPtr,
  269.                                  long                     textLen,
  270.                                  DateCachePtr             theCache,
  271.                                  long *                    lengthUsed,
  272.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF6, 0xA8B5);
  273.  
  274. EXTERN_API( StringToDateStatus )
  275. StringToTime                    (Ptr                     textPtr,
  276.                                  long                     textLen,
  277.                                  DateCachePtr             theCache,
  278.                                  long *                    lengthUsed,
  279.                                  LongDateRec *            dateTime)                            FOURWORDINLINE(0x2F3C, 0x8214, 0xFFF4, 0xA8B5);
  280.  
  281. EXTERN_API( void )
  282. LongDateToSeconds                (const LongDateRec *    lDate,
  283.                                  LongDateTime *            lSecs)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF2, 0xA8B5);
  284.  
  285. EXTERN_API( void )
  286. LongSecondsToDate                (const LongDateTime *    lSecs,
  287.                                  LongDateRec *            lDate)                                FOURWORDINLINE(0x2F3C, 0x8008, 0xFFF0, 0xA8B5);
  288.  
  289. EXTERN_API( ToggleResults )
  290. ToggleDate                        (LongDateTime *            lSecs,
  291.                                  LongDateField             field,
  292.                                  DateDelta                 delta,
  293.                                  short                     ch,
  294.                                  const TogglePB *        params)                                FOURWORDINLINE(0x2F3C, 0x820E, 0xFFEE, 0xA8B5);
  295.  
  296. EXTERN_API( short )
  297. ValidDate                        (const LongDateRec *    vDate,
  298.                                  long                     flags,
  299.                                  LongDateTime *            newSecs)                            FOURWORDINLINE(0x2F3C, 0x820C, 0xFFE4, 0xA8B5);
  300.  
  301.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  302.                                                                                             #pragma parameter __D0 ReadDateTime(__A0)
  303.                                                                                             #endif
  304. EXTERN_API( OSErr )
  305. ReadDateTime                    (unsigned long *        time)                                ONEWORDINLINE(0xA039);
  306.  
  307.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  308.                                                                                             #pragma parameter GetDateTime(__A0)
  309.                                                                                             #endif
  310. EXTERN_API( void )
  311. GetDateTime                        (unsigned long *        secs)                                TWOWORDINLINE(0x20B8, 0x020C);
  312.  
  313.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  314.                                                                                             #pragma parameter __D0 SetDateTime(__D0)
  315.                                                                                             #endif
  316. EXTERN_API( OSErr )
  317. SetDateTime                        (unsigned long             time)                                ONEWORDINLINE(0xA03A);
  318.  
  319.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  320.                                                                                             #pragma parameter SetTime(__A0)
  321.                                                                                             #endif
  322. EXTERN_API( void )
  323. SetTime                            (const DateTimeRec *    d)                                    TWOWORDINLINE(0xA9C7, 0xA03A);
  324.  
  325.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  326.                                                                                             #pragma parameter GetTime(__A0)
  327.                                                                                             #endif
  328. EXTERN_API( void )
  329. GetTime                            (DateTimeRec *            d)                                    THREEWORDINLINE(0x2038, 0x020C, 0xA9C6);
  330.  
  331. EXTERN_API( void )
  332. DateToSeconds                    (const DateTimeRec *    d,
  333.                                  unsigned long *        secs);
  334.  
  335.                                                                                             #if TARGET_OS_MAC && TARGET_CPU_68K && !TARGET_RT_MAC_CFM
  336.                                                                                             #pragma parameter SecondsToDate(__D0, __A0)
  337.                                                                                             #endif
  338. EXTERN_API( void )
  339. SecondsToDate                    (unsigned long             secs,
  340.                                  DateTimeRec *            d)                                    ONEWORDINLINE(0xA9C6);
  341.  
  342.  
  343. /*
  344.     These routine are available in InterfaceLib using their old name.
  345.     Macros allow using the new names in all source code.
  346. */
  347. EXTERN_API( void )
  348. IUDateString                    (long                     dateTime,
  349.                                  DateForm                 longFlag,
  350.                                  Str255                 result)                                TWOWORDINLINE(0x4267, 0xA9ED);
  351.  
  352. EXTERN_API( void )
  353. IUTimeString                    (long                     dateTime,
  354.                                  Boolean                 wantSeconds,
  355.                                  Str255                 result)                                THREEWORDINLINE(0x3F3C, 0x0002, 0xA9ED);
  356.  
  357. EXTERN_API( void )
  358. IUDatePString                    (long                     dateTime,
  359.                                  DateForm                 longFlag,
  360.                                  Str255                 result,
  361.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x000E, 0xA9ED);
  362.  
  363. EXTERN_API( void )
  364. IUTimePString                    (long                     dateTime,
  365.                                  Boolean                 wantSeconds,
  366.                                  Str255                 result,
  367.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0010, 0xA9ED);
  368.  
  369. EXTERN_API( void )
  370. IULDateString                    (LongDateTime *            dateTime,
  371.                                  DateForm                 longFlag,
  372.                                  Str255                 result,
  373.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0014, 0xA9ED);
  374.  
  375. EXTERN_API( void )
  376. IULTimeString                    (LongDateTime *            dateTime,
  377.                                  Boolean                 wantSeconds,
  378.                                  Str255                 result,
  379.                                  Handle                 intlHandle)                            THREEWORDINLINE(0x3F3C, 0x0016, 0xA9ED);
  380.  
  381.  
  382. #if CALL_NOT_IN_CARBON
  383. #define DateString(dateTime, longFlag, result, intlHandle) \
  384.          IUDatePString( dateTime, longFlag, result, intlHandle)
  385. #define TimeString(dateTime, wantSeconds, result, intlHandle) \
  386.          IUTimePString(dateTime, wantSeconds, result, intlHandle)
  387. #define LongDateString(dateTime, longFlag, result, intlHandle) \
  388.          IULDateString(dateTime, longFlag, result, intlHandle)
  389. #define LongTimeString(dateTime, wantSeconds, result, intlHandle) \
  390.          IULTimeString(dateTime, wantSeconds, result, intlHandle)
  391. #endif /* CALL_NOT_IN_CARBON */
  392. #if OLDROUTINENAMES
  393. #define String2Date(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  394.          StringToDate(textPtr, textLen, theCache, lengthUsed, dateTime)
  395. #define String2Time(textPtr, textLen, theCache, lengthUsed, dateTime)  \
  396.          StringToTime(textPtr, textLen, theCache, lengthUsed, dateTime)
  397. #define LongDate2Secs(lDate, lSecs) LongDateToSeconds(lDate, lSecs)
  398. #define LongSecs2Date(lSecs, lDate) LongSecondsToDate(lSecs, lDate)
  399. #define Date2Secs(d, secs) DateToSeconds(d, secs)
  400. #define Secs2Date(secs, d) SecondsToDate(secs, d)
  401. #endif  /* OLDROUTINENAMES */
  402.  
  403. EXTERN_API_C( void )
  404. iudatestring                    (long                     dateTime,
  405.                                  DateForm                 longFlag,
  406.                                  char *                    result);
  407.  
  408. EXTERN_API_C( void )
  409. iudatepstring                    (long                     dateTime,
  410.                                  DateForm                 longFlag,
  411.                                  char *                    result,
  412.                                  Handle                 intlHandle);
  413.  
  414. EXTERN_API_C( void )
  415. iutimestring                    (long                     dateTime,
  416.                                  Boolean                 wantSeconds,
  417.                                  char *                    result);
  418.  
  419. EXTERN_API_C( void )
  420. iutimepstring                    (long                     dateTime,
  421.                                  Boolean                 wantSeconds,
  422.                                  char *                    result,
  423.                                  Handle                 intlHandle);
  424.  
  425. EXTERN_API_C( void )
  426. iuldatestring                    (LongDateTime *            dateTime,
  427.                                  DateForm                 longFlag,
  428.                                  char *                    result,
  429.                                  Handle                 intlHandle);
  430.  
  431. EXTERN_API_C( void )
  432. iultimestring                    (LongDateTime *            dateTime,
  433.                                  Boolean                 wantSeconds,
  434.                                  char *                    result,
  435.                                  Handle                 intlHandle);
  436.  
  437.  
  438.  
  439.  
  440.  
  441. #if PRAGMA_STRUCT_ALIGN
  442.     #pragma options align=reset
  443. #elif PRAGMA_STRUCT_PACKPUSH
  444.     #pragma pack(pop)
  445. #elif PRAGMA_STRUCT_PACK
  446.     #pragma pack()
  447. #endif
  448.  
  449. #ifdef PRAGMA_IMPORT_OFF
  450. #pragma import off
  451. #elif PRAGMA_IMPORT
  452. #pragma import reset
  453. #endif
  454.  
  455. #ifdef __cplusplus
  456. }
  457. #endif
  458.  
  459. #endif /* __DATETIMEUTILS__ */
  460.  
  461.